#!/usr/bin/python3
import sys

try:
    t = int(input())
    for x in range(t):
        n = int(input())
        if n < 1 or n > 100000:
            sys.exit(0)
        a = input()
        a_s = a.split()
        q = int(input())
        print("Case #%d: " % (x + 1))
        for i in range(q):
            sum_1 = 0
            lrs = input()
            lr = lrs.split()
            left = int(lr[0])
            right = int(lr[1])
            k = 1
            for j in range(left, right + 1):
                sum_1 = sum_1 + int(a_s[j - 1]) * k
                k = k + 1
            print(sum_1)


except ValueError:
    pass
except IndexError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
